import React, { FC } from 'react'
import { Form, Button } from 'antd'
import "./index.scss"
import { FormInstance } from 'antd/lib/form'
import { useForm } from 'antd/lib/form/Form'
const defaultProps = {
    layout: 'inline' as any,
}

interface IProps {
    handleSearch?: (values: any) => void
}
const IMSearchBar: FC<IProps> = ({ children, handleSearch }) => {
    const [formRef] = useForm()
    const onSearch = () => {
        const values = formRef.getFieldsValue()
        handleSearch && handleSearch(values)
    }
    const onReset = () => {
        formRef.resetFields()
        handleSearch && handleSearch(formRef.getFieldsValue())
    }
    return <div className="im_pic_list_search">
        <Form
            {...defaultProps}
            form={formRef}
            className="im_pic_list_search_form"
        >
            {children}
            <Form.Item>
                <Button type="primary" onClick={onSearch}>搜索</Button>
                <Button type="ghost" onClick={onReset}>重置</Button>
            </Form.Item>
        </Form>
    </div>
}

export default IMSearchBar